package com.lsj.fileutil;

import com.google.gson.Gson;
import com.lsj.pojo.Type;

import java.util.ArrayList;
import java.util.List;

public class test {
    public List<String> read(){
        FileUtil f=new FileUtil();
        try {
            return f.read("f:/test/type/type.txt");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public void write(){
        FileUtil f=new FileUtil();
        List<Type> list = new ArrayList<Type>();
        List<String> strType = new ArrayList<String>();
        Gson gs=new Gson();
        for(int i=0;i<5;i++){
            Type tp=new Type();
            tp.setTypeurl("/aaaaa/"+i);
            tp.setTypename("测试类型:"+i);
            list.add(tp);
            String str = gs.toJson(tp);
            Type tp2= gs.fromJson(str,Type.class);
            strType.add(str);
        }
        try {
            f.write("f:/test/type/type.txt",strType);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        List <String> l = new test().read();
        Gson gs=new Gson();
        for(String str:l){
            Type tp2= gs.fromJson(str,Type.class);
            System.out.println( tp2.getTypeurl()+"  "+tp2.getTypename());
        }
//        new test().write();
    }

}
